/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author tank
 */

import java.util.Scanner;
public class task1
{
	public long[] a;                 //  array a
	public int nElems;               // number of data items
	public task1(int max)          // constructor
    {
    a = new long[max];                 // create the array
    nElems = 0;
    }
//--------------------------------------------------------------
 public void insert(long value)    // put element into array
    {
    a[nElems] = value;             // insert it
    nElems++;                      // increment size
    }
//--------------------------------------------------------------
 public void display()             // displays array contents
    {
    for(int j=0; j<nElems; j++)       // for each element,
       System.out.print(a[j] + " ");  // display it
    System.out.println("");
    }
//--------------------------------------------------------------
 public void bubbleSort()
    {
    int out, in;

    for(out=nElems-1; out>1; out--)   // outer loop (backward)
       for(in=0; in<out; in++)        // inner loop (forward)
          if( a[in] > a[in+1] )       // out of order?
             swap(in, in+1);          // swap them
    }  // end bubbleSort()
//--------------------------------------------------------------
 public void swap(int one, int two)
    {
    long temp = a[one];
    a[one] = a[two];
    a[two] = temp;
    }
//--------------------------------------------------------------
}  // end class
////////////////////////////////////////////////////////////////
class BubbleSortApp
 {
 public static void main(String[] args)
    {long sum = 0;
	 boolean over = false;
	int count = 0;
    int maxSize = 100;            // array size
    task1 arr;                 // reference to array
    arr = new task1(maxSize);  // create the array
    System.out.println("Please enter integer numbers, end with a negative number:");
    do{
    Scanner input= new Scanner(System.in);
    System.out.println("Enter a number:");
    int a = input.nextInt();
    if (a > 0)
    {
	   arr.insert(a);
	   count=count +1;
	   sum = sum + a;
	   continue;
    }
   over = true;
   if (a < 0)
   {                // display items
   arr.bubbleSort();             // bubble sort them
   int max = count-1;
   System.out.println("Largest:"+arr.a[max]);
   System.out.println("Smallest:"+arr.a[0]);
   System.out.println("Average:"+sum/count);
   System.out.println("Count:"+count);
   System.exit(0);
   }
    }while(over = true);
    }
    }// end main()
